<?php


namespace App\Utils\Service;

use Illuminate\Support\Facades\Redis;
use think\exception\ValidateException;

class SMSBao
{
    public function makeReservation($phone){
        try {
            $smsapi = "http://api.smsbao.com/";
            $user = config('smsbao.user');
            $pass = config('smsbao.pass');
            $code = rand(1000,9999);
            $content="【卧龙】尊敬的用户，您正在在品优购平台进行帐号注册，您的验证为:{$code},验证有效期为5分钟、过期失效、请勿泄漏";
            $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
            $result =file_get_contents($sendurl);
            $redis = \App\Utils\Lib\Redis::createRedisObject();
            $redis->select(2);
             $key = 'code'.$phone;
             $redis->setex($key,600,$code);

            return $result;
        }catch (ValidationException $e){
            return $e->getMessage();
        }
    }


}
